import 'package:hive/hive.dart';

@HiveType(typeId: 1)
class UserInfo extends HiveObject {
  @HiveField(0)
  String name; //名称
  @HiveField(1)
  int age; //年龄

  UserInfo({this.name = "", this.age = 0});

  @override
  String toString() {
    return "name:$name, age:$age";
  }
}

class UserInfoAdapter extends TypeAdapter<UserInfo> {
  @override
  UserInfo read(BinaryReader reader) {
    return UserInfo(name: reader.readString(), age: reader.readInt());
  }

  @override
  int get typeId => 1;

  ///typeId唯一，0 到 223 之间

  @override
  void write(BinaryWriter writer, UserInfo obj) {
    writer.writeString(obj.name);
    writer.writeInt(obj.age);
  }
}
